<template> 
   <div class="JNPF-common-layout"> 
    <div class="JNPF-common-layout-center"> 
     <el-row class="JNPF-common-search-box" :gutter="16"> 
      <el-form @submit.native.prevent="">
		<el-col :span="6">
			<el-form-item label="重大危险源名称">
				<el-input v-model="query.zdwxymc" placeholder="重大危险源名称" clearable  />
			</el-form-item>
		</el-col>
		<el-col :span="6">
			<el-form-item label="危险源单元类型">
				<el-select v-model="query.dylx" placeholder="危险源单元类型" clearable >
					<el-option v-for="(item, index) in dylxOptions" :key="index" :label="item.fullName" :value="item.id"  />
				</el-select>
			</el-form-item>
		</el-col>
		<el-col :span="6">
			<el-form-item label="危险源等级">
				<el-select v-model="query.wxydj" placeholder="危险源等级" clearable >
					<el-option v-for="(item, index) in wxydjOptions" :key="index" :label="item.fullName" :value="item.id"  />
				</el-select>
			</el-form-item>
		</el-col>
		<template v-if="showAll">
		<el-col :span="6">
			<el-form-item label="投用日期">
				<el-date-picker v-model="query.tyrq" placeholder="投用日期" clearable  />
			</el-form-item>
		</el-col>
		</template>

        <el-col :span="6"> 
            <el-form-item> 
                <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button> 
                <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button> 
				<el-button type="text" icon="el-icon-arrow-down" @click="showAll=true" v-if="!showAll">展开</el-button>
				<el-button type="text" icon="el-icon-arrow-up" @click="showAll=false" v-else>收起</el-button>

            </el-form-item> 
       </el-col> 
      </el-form> 
     </el-row> 
     <div class="JNPF-common-layout-main JNPF-flex-main"> 
      <div class="JNPF-common-head"> 
       <div> 
		 <el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">
		 新增
		 </el-button>
		 <!-- <el-button type="text" icon="el-icon-download" @click="exportData()">
		 导出
		 </el-button> -->

       </div> 
       <div class="JNPF-common-head-right"> 
        <el-tooltip effect="dark" content="刷新" placement="top"> 
         <el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false" @click="reset()" /> 
        </el-tooltip> 
        <screenfull />
       </div> 
      </div> 
      <JNPF-table v-loading="listLoading" :data="list">
		<el-table-column prop="zdwxybm" label="重大危险源编码" align="left" />
		<el-table-column prop="zdwxymc" label="重大危险源名称" align="left" />
		<el-table-column label="危险源单元类型"  prop="dylx" algin="left">
			<template slot-scope="scope">{{ scope.row.dylx | dynamicText(dylxOptions) }}</template>
		</el-table-column>
		<el-table-column label="危险源等级"  prop="wxydj" algin="left">
			<template slot-scope="scope">{{ scope.row.wxydj | dynamicText(wxydjOptions) }}</template>
		</el-table-column>
		<el-table-column label="地理位置"  prop="dz" algin="left">
			<template slot-scope="scope">{{ scope.row.dz | dynamicText(dzOptions) }}</template>
		</el-table-column>
		<el-table-column label="管辖部门"  prop="gxbm" algin="left">
			<template slot-scope="scope">{{ scope.row.gxbm | dynamicText(gxbmOptions) }}</template>
		</el-table-column>
		<el-table-column label="管控负责人"  prop="gkfzr" algin="left">
			<template slot-scope="scope">{{ scope.row.gkfzr | dynamicText(gkfzrOptions) }}</template>
		</el-table-column>
		<el-table-column prop="tyrq" label="投用日期" align="left" />

        <el-table-column label="操作" fixed="right" width="150">
            <template slot-scope="scope">
            <!-- <el-button type="text" @click="addOrUpdateHandle(scope.row.id)" >
            编辑
            </el-button> -->
            <el-button type="text" @click="handleDel(scope.row.id)" class="JNPF-table-delBtn">
            删除
            </el-button>
            <el-button type="text" @click="addOrUpdateHandle(scope.row.id,true)" >
            详情
            </el-button>
            </template>
        </el-table-column>
       
      </JNPF-table> 
      <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />

     </div> 
    </div> 
    <JNPFForm v-if="formVisible" ref="JNPFForm" @refresh="refresh" /> 
    <exportbox v-if="exportBoxVisible" ref="ExportBox" @download="download" /> 
   </div> 
</template> 
<script>
    import request from '@/utils/request'
    import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
    import JNPFForm from './Form'
    import ExportBox from './ExportBox'
    import {previewDataInterface} from '@/api/systemData/dataInterface'

    export default {
        components: {JNPFForm, ExportBox},
        data() {
            return {
                showAll: false,
                query: {
					zdwxymc:undefined,
					dylx:undefined,
					wxydj:undefined,
					tyrq:undefined,

                },
                defaultProps: {
                    children: 'children',
                    label: 'fullName'
                },
                list: [],
                listLoading: true,
                total: 0,
                listQuery: {
					currentPage: 1,
					pageSize: 20,
                    sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
                columnList: [
					{prop: 'zdwxybm', label: '重大危险源编码'},
					{prop: 'zdwxymc', label: '重大危险源名称'},
					{prop: 'dylx', label: '危险源单元类型'},
					{prop: 'wxydj', label: '危险源等级'},
					{prop: 'dz', label: '地理位置'},
					{prop: 'gxbm', label: '管辖部门'},
					{prop: 'gkfzr', label: '管控负责人'},
					{prop: 'tyrq', label: '投用日期'},

                ],
				dzOptions:[],
				gxbmOptions:[],
				gkfzrOptions:[],
				knsgOptions:[{"fullName":"爆炸","id":"爆炸"},{"fullName":"火灾","id":"火灾"},{"fullName":"灼烫","id":"灼烫"},{"fullName":"中毒和窒息","id":"中毒和窒息"},{"fullName":"其他","id":"其他"}],
				dylxOptions:[{"fullName":"储存单元","id":"储存单元"},{"fullName":"生产单元","id":"生产单元"}],
				wxydjOptions:[{"fullName":"一级","id":"01"},{"fullName":"二级","id":"02"},{"fullName":"三级","id":"03"},{"fullName":"四级","id":"04"},{"fullName":"不构成危化品重大危险源","id":"05"}],

            }
        },
        computed: {},
        created() {
            this.initData();
            this.getDzOptions();
            this.getGxbmOptions();
            this.getGkfzrOptions();
        },
        methods: {
            getDzOptions(){
                getDictionaryDataSelector('dae93f2fd7cd4df999d32f8750fa6a1e').then(res => {
                    this.dzOptions = res.data.list
                })
            },
            getGxbmOptions(){
                getDictionaryDataSelector('dae93f2fd7cd4df999d32f8750fa6a1e').then(res => {
                    this.gxbmOptions = res.data.list
                })
            },
            getGkfzrOptions(){
                getDictionaryDataSelector('dae93f2fd7cd4df999d32f8750fa6a1e').then(res => {
                    this.gkfzrOptions = res.data.list
                })
            },

            initData() {
                // this.listLoading = false; //-
                this.listLoading = true;
                let query = {
                    ...this.listQuery,
                    ...this.query
                };
                request({
                    // url: `/api/System/ZDWXY`,
                    url: `/api/System/QYSCZDWXY`,
                    method: 'get',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    this.listLoading = false
                    this.$nextTick(() => {
                        this.tableHeight = "100%"
                    });
                })
            },
            handleDel(id) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    request({
                        // url: `/api/System/ZDWXY/${id}`,
                        url: `/api/System/QYSCZDWXY/${id}`,
                        method: 'DELETE'
                    }).then(res => {
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: () => {
                                this.initData()
                            }
                        });
                    })
                }).catch(() => {
                });
            },
            addOrUpdateHandle(id,isDetail) {
                this.formVisible = true
                this.$nextTick(() => {
                    this.$refs.JNPFForm.init(id,isDetail)
                })
            },
            exportData() {
                this.exportBoxVisible = true
                this.$nextTick(() => {
                    this.$refs.ExportBox.init(this.columnList)
                })
            },
            download(data) {
                let query = {...data, ...this.listQuery, ...this.query}
                request({
                    // url: `/api/System/ZDWXY/Actions/Export`,
                    url: `/api/System/QYSCZDWXY/Actions/Export`,
                    method: 'POST',
                    data: query
                }).then(res => {
                    if (!res.data.url) return
                    window.location.href = this.define.comUrl + res.data.url
                    this.$refs.ExportBox.visible = false
                    this.exportBoxVisible = false
                })
            },
            search() {
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.formVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            }
        }
    }
</script>